/**
 * author:Administrator
 * date:2016/2/24
 * desc:TODO
 */
'use strict';


let seq = 1;
let list = {};

class WareSnapshotRepoImpl {

  static * genId() {
    return 'wareSnapshot_' + (seq++);
  }

  static * find(id) {
    return list[id];
  }

  static *store(snapshot) {
    if (!snapshot.id) snapshot.id = yield WareSnapshotRepoImpl.genId();
    list[snapshot.id] = snapshot;
  }

  static * findByWare(wareInfo) {
    //console.log('wareInfo', wareInfo);
    //console.log('all snapshot', list);
    let wareId = wareInfo.wareId;
    let ver = wareInfo.ver;

    let ids = Object.keys(list);
    for (var id of ids) {
      let item = list[id];
      if (item.wareId == wareId && item.ver == ver)
        return item;
    }
    return null;
  }

}
module.exports = WareSnapshotRepoImpl;